package temp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import temp.dao.HibernateTest;
import temp.model.Text;

/**
 * @author Paziy Evgeniy
 * @version 1.0
 * @since 09.03.14
 */
@Controller
@RequestMapping
public class Hello {

    @Autowired
    private HibernateTest dao;


    @RequestMapping(method = RequestMethod.GET)
    public String sayHello(Model model) {

        Text text = new Text();
        text.setText("Set text to DataBase");

        dao.create(text);

        Text fromDB = dao.get(text.getId());

        model.addAttribute("text", fromDB);

        return "index";
    }
}
